Compilers can communicate the location of user variables at run time to debuggers, program analysis tools, run-time monitors and the like. However, as compilers gained more and more optimization passes, the lack of infrastructure to retain a correspondence between source-level and run-time constructs has become a serious problem. As a result, a compiler may fail to emit location information for some local user variables or a compiler may emit locations that make it seem like variables hold unexpected values at certain points in the program.
One solution for improving debug information is to annotate the internal representation of a program, held by the compiler, with statements that bound user variables to expressions that represent the variables' location or value. FIG. 1 illustrates a prior art mechanism for annotating an internal representation of a program in a compiler system known as GNU compiler collection (GCC).
Referring to FIG. 1, source code statements 102 represent portions of an exemplary program. The source code statements 102 are converted into an internal representation 104, which includes annotations that bound user variables to debug expressions. In particular, a statement # v=>_n means that a user variable v is bound to the value held by the internal representation name_n.
An optimizing compiler realizes that—7 and —5 compute the same value, and —8 and —6 compute the same value, as shown by statements 110. Hence, the compiler discards the duplicate computations as part of the compiler optimization. In addition, the compiler realizes that —9 is assigned to zero (i.e., —6-—6), as shown by statement 112. As a result, all internal names are left unreferenced, except for the uses in debug statements 106.
As all definitions, from —1 to —8, have become unused in the executable code (excluding debug statements), the compiler is supposed to discard them while retaining as much debug information as it can. The result is a set of statements 108. As shown, expression 110 that computes the value for the optimized-away user variable f has grown exponentially, increasing memory consumption and resulting in CPU overhead when emitting debug information.